package com.ruoyi.project.zzuser.apply.controller;

import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.zzuser.apply.domain.ZzuserApply;
import com.ruoyi.project.zzuser.apply.service.ZzuserApplyService;
import com.ruoyi.project.zzuser.info.domain.ZzuserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/zzuser/apply")
public class ZzuserApplyController extends BaseController {

    @Autowired
    private ZzuserApplyService zzuserApplyService;

    private String prefix = "zzuser/apply";

    private ServerConfig serverConfig = new ServerConfig();

    @GetMapping()
    public String apply()
    {
        return prefix + "/apply";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(String title, String applicant)
    {
        startPage();
        List<ZzuserInfo> list = zzuserApplyService.selectApplyList(title, applicant);
        return getDataTable(list);
    }

    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    @PostMapping("/add/submit")
    @ResponseBody
    public AjaxResult submit(ZzuserApply zzuserApply) {
        return toAjax(zzuserApplyService.addApply(zzuserApply));
    }

    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(zzuserApplyService.deleteApply(ids));
    }

    @GetMapping("/edit/{applyId}")
    public String edit(@PathVariable("applyId") Long applyId, ModelMap mmap) {

        mmap.put("apply", zzuserApplyService.selectApplyById(applyId));
        return prefix + "/edit";
    }

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZzuserApply zzuserApply) {
        return toAjax(zzuserApplyService.updateApply(zzuserApply));
    }

}
